<template>
	<view class="subform">
		<u-form labelPosition="left" :model="from" :rules="rulesFrom" ref="form">
			<homeCard v-for="(item,index) in fromData" :title="item.title" :key="index">
				<template v-for="(itemValue,index1) in item.fromItem">
					<u-form-item :required='itemValue.require' v-if="itemValue.type=='input'" :label="itemValue.label"
						:labelWidth='itemValue.labelWidth' :prop="itemValue.key" borderBottom>
						<view style="display: flex;align-items: center;" v-if="itemValue.key != 'transferPerson'">
							<u--input inputAlign='right' :type="itemValue.typeValue" v-model="from[itemValue.key]"
								border="none" :placeholder="itemValue.placeholder" @change="bindFormValueChange(from, itemValue.key)">
							</u--input>
							<text style="margin-left:10rpx;">{{itemValue.dw}}</text>
						</view>
						<!-- <view style="display: flex;align-items: center;" v-if="itemValue.key == 'transferPerson'">
						<input type="text" v-model="from[itemValue.key]" disabled placeholder-style="color: #e4e4e4;" placeholder="未获取到交接人" style="flex: 1; text-align: right; font-size: 30rpx;">
						<text style="margin-left:10rpx;">{{itemValue.dw}} 11</text>
					</view> -->
					</u-form-item>
					<u-form-item v-if="itemValue.type=='mark'">
						<p class="mark">每个空桶重4.3kg</p>
					</u-form-item>
					<u-form-item v-if="itemValue.type=='select'" :label="itemValue.label"
						:labelWidth='itemValue.labelWidth' :prop="itemValue.key" borderBottom @click="showSexSelect">
						<!-- <u--input v-model="from[itemValue.key]" disabled disabledColor="#ffffff" :styles="{'text-align': 'right'}" :placeholder="itemValue.placeholder" border="none">
						</u--input> -->
						<input type="text" v-model="from[itemValue.key]" disabled placeholder-style="color: #e4e4e4;"
							placeholder="未获取到交接人" style="flex: 1; text-align: right; font-size: 30rpx;">
						<template v-slot:right>
							<u-icon name="arrow-right" size="14"></u-icon>
						</template>
					</u-form-item>
				</template>
			</homeCard>
			<slot></slot>
		</u-form>
	</view>
</template>

<script>
	export default {
		props: {
			fromData: {
				type: Array,
				default: []
			},
			rules: {
				type: Object,
				default: {}
			},
			userInfo: {
				type: Object,
				default: {}
			},
		},
		name: "From",
		watch: {
			userInfo: {
				deep: true,
				handler(newValue, oldvalue) {
					console.log('newValuenewValue', newValue)
					Object.keys(newValue).map(key => {
						this.$set(this.from, key, newValue[key])
					})
				},
			}
		},
		data() {
			return {
				rulesFrom: this.rules,
				from: JSON.parse(JSON.stringify(this.userInfo)),
			};
		},
		methods:{
			showSexSelect(){
				this.$emit('showSelect')
			},
			bindPickerChange(e){
				console.log('e:', e)
			},
      bindFormValueChange(form, field) {
        this.$emit('fieldChange', field, form)
      }
		}
	}
</script>

<style scoped>
	.submit {
		width: 710rpx;
		height: 100rpx;
		opacity: 0.5;
		background: #3db020;
		border-radius: 10rpx;
	}

	.subform {
		padding-bottom: 20rpx;
	}

	.mark {
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC-Regular;
		font-weight: Regular;
		text-align: right;
		color: #999999;
		text-align: right;
		width: 100%;
	}
</style>
